package com.jiadakeji.ppm.api.v1;

import com.jiadakeji.ppm.api.common.JsonResult;
import com.jiadakeji.ppm.common.utils.StringUtils;
import com.jiadakeji.ppm.common.web.BaseController;
import com.jiadakeji.ppm.modules.business.entity.Repair;
import com.jiadakeji.ppm.modules.business.service.RepairService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController("v1_repairController")
@RequestMapping(value = "${apiPath}/v1/repair")
public class RepairController extends BaseController {
    @Autowired
    private RepairService repairService;

    @RequestMapping(value = "/putRepair")
    @ApiOperation(value = "插入保修",httpMethod = "POST",consumes="application/json",notes="根据id")
    public JsonResult<String> putRepair(@RequestBody Repair repair, HttpServletRequest request, HttpServletResponse response){
        JsonResult<String> result = new JsonResult<>();
        if(StringUtils.isBlank(repair.getRoomId())){
            return result.setCodeAndMessage(-1,"roomId不能为空");
        }
        if(StringUtils.isBlank(repair.getCustomerId())){
            return result.setCodeAndMessage(-1,"customerId不能为空");
        }
        repair.setStatus("0");
        repairService.save(repair);
        return result;
    }

    @RequestMapping(value = "/getMyRepair")
    @ApiOperation(value = "插入保修",httpMethod = "POST",consumes="application/json",notes="根据id")
    public JsonResult<List<Repair>> getMyRepair(@RequestBody Repair repair, HttpServletRequest request, HttpServletResponse response){
        JsonResult<List<Repair>> result = new JsonResult<>();
        if(StringUtils.isBlank(repair.getCustomerId())){
            return result.setCodeAndMessage(-1,"customerId不能为空");
        }
        List<Repair> list = repairService.findList(repair);
        result.setData(list);
        return result;
    }
}
